package reflect;


import java.lang.reflect.Field;

// 访问属性
public class ReflectDemo8
{
    public static void main(String[] args) throws Exception
    {
        Class aClass = Class.forName("reflect.Teacher");
        Object o = aClass.newInstance();
        Field type = aClass.getField("Type");
        type.set(o,"TEACHER");
        System.out.println(o);
        // 访问私有属性
        Field name = aClass.getDeclaredField("name");
        name.setAccessible(true);
        name.set(o,"杨宁GZZ");
        name.setAccessible(false);
        System.out.println(o);
    }
}
